#include "Vector2D.h"
#include <math.h>

Vector2D::Vector2D()
{
	X = 0;
	Y = 0;
}

Vector2D::Vector2D(double x,double y)
{
	X = x;
	Y = y;
}

Vector2D::Vector2D(const Vector2D & v)
{
	X = v.X;
	Y = v.Y;
}

Vector2D::Vector2D(const Vector2D & from,const Vector2D & to)
{
	X = to.X - from.X;
	Y = to.Y - from.Y;
}

Vector2D & Vector2D::operator= (const Vector2D & v)
{
	X = v.X;
	Y = v.Y;
	return *this;
}

Vector2D & Vector2D::operator+= (const Vector2D & v)
{
	X += v.X;
	Y += v.Y;
	return *this;
}

Vector2D Vector2D::operator+ (const Vector2D & v) const
{
	Vector2D t = *this;
	t += v;
	return t;
}

Vector2D & Vector2D::operator-= (const Vector2D & v)
{
	X -= v.X;
	Y -= v.Y;
	return *this;
}

Vector2D Vector2D::operator- (const Vector2D & v) const
{
	Vector2D t = *this;
	t -= v;
	return t;
}

Vector2D & Vector2D::operator*= (const double a)
{
	X *= a;
	Y *= a;
	return *this;
}

Vector2D Vector2D::operator* (const double a)const
{
	Vector2D t = *this;
	t *= a;
	return t;
}

Vector2D operator* (const double a,const Vector2D & v)
{
	return Vector2D(v.X*a,v.Y*a);
}

Vector2D & Vector2D::operator/= (const double a)
{
	X /= a;
	Y /= a;
	return *this;
}

Vector2D Vector2D::operator/ (const double a)const
{
	Vector2D t = *this;
	t /= a;
	return t;
}

Vector2D Vector2D::crossProduct(const Vector2D & v)const
{
	Vector2D t;
	t.X = X*v.Y;
	t.Y = -Y*v.X;
	return t;
}

double Vector2D::length()const
{
	return sqrt( X*X + Y*Y);
}

Vector2D & Vector2D::normalize()
{
	(*this) /= length();
	return (*this);
}
double Vector2D::dot(const Vector2D& vec) const
{
	return X*vec.X + Y*vec.Y;
}
double Vector2D::angleSigned( const Vector2D& vec ) const
{
	Vector2D vC=this->crossProduct(vec);
	double angle=atan2(vC.length(),this->dot(vec));
	angle=vC.dot(Vector2D(0,1)) < 0.0 ? -angle : angle;
	return angle;
}

